package cn.edu.hqu.exp.courseselection.web;

import java.security.Principal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.edu.hqu.exp.courseselection.domain.User;
import cn.edu.hqu.exp.courseselection.repository.UserRepository;
import lombok.extern.slf4j.Slf4j;

@Controller
@RequestMapping("/")
public class HomeController {
	 private UserRepository userRepo;
	 
	 @Autowired
	 public HomeController(UserRepository userRepo) {
		 this.userRepo = userRepo;
	 }
	 
	 @GetMapping
	 public String homeControll(Model model, Principal principal) {
		 if(principal != null) {
				String username=principal.getName();
				User user=userRepo.findByUsername(username);
				model.addAttribute("nowUser",user);
		 }
		 return "home";
	 }
}
